package com.ruoyi.web.controller.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.course.domain.LwControls;
import com.ruoyi.course.domain.LwDetection;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.LwCourse;
import com.ruoyi.course.service.ILwCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产过程管理Controller
 * 
 * @author sll
 * @date 2023-08-18
 */
@RestController
@RequestMapping("/course/course")
public class LwCourseController extends BaseController
{
    @Autowired
    private ILwCourseService lwCourseService;

    /**
     * 查询生产过程管理列表
     */
    @PreAuthorize("@ss.hasPermi('course:course:list')")
    @GetMapping("/list")
    public TableDataInfo list(LwCourse lwCourse)
    {
        startPage();
        List<LwCourse> list = lwCourseService.selectLwCourseList(lwCourse);
        return getDataTable(list);
    }

    /**
     * 查询检测记录列表
     */

    @Anonymous
//    @PreAuthorize("@ss.hasPermi('course:course:getDetection')")
    @GetMapping("/getDetection")
    public AjaxResult getDetection(@RequestParam Long courseId ,@RequestParam Long status)
    {
        System.out.println("-------------------------------------------------------");
        return success(lwCourseService.getDetection(courseId,status));
    }

    /**
     * 查询入库记录 getWarehousinginfo
     */

    @Anonymous
//    @PreAuthorize("@ss.hasPermi('course:course:getWarehousinginfo')")
    @GetMapping("/getWarehousinginfo")
    public AjaxResult getWarehousinginfo(@RequestParam Long courseId ,@RequestParam String flow)
    {
        return success(lwCourseService.getWarehousinginfo(courseId,flow));
    }

    /**
     * 查询生产操作列表（后焊/装配、老化）
     */

    @Anonymous
//    @PreAuthorize("@ss.hasPermi('course:course:getControls')")
    @GetMapping("/getControls")
    public AjaxResult getControls(@RequestParam Long courseId ,@RequestParam String flow)
    {
        return success(lwCourseService.getControls(courseId,flow));
    }

    /**
     * 导出生产过程管理列表
     */
    @PreAuthorize("@ss.hasPermi('course:course:export')")
    @Log(title = "生产过程管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LwCourse lwCourse)
    {
        List<LwCourse> list = lwCourseService.selectLwCourseList(lwCourse);
        ExcelUtil<LwCourse> util = new ExcelUtil<LwCourse>(LwCourse.class);
        util.exportExcel(response, list, "生产过程管理数据");
    }

    /**
     * 获取生产过程管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:course:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lwCourseService.selectLwCourseById(id));
    }

    /**
     * 新增生产过程管理
     */
    @PreAuthorize("@ss.hasPermi('course:course:add')")
    @Log(title = "生产过程管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LwCourse lwCourse)
    {
//        int i = lwCourseService.insertLwCourse(lwCourse);
//        if (i == -1){
//            return AjaxResult.error("原材料不足");
//        }else {
//            return toAjax(i);
//        }
        return lwCourseService.insertLwCourse(lwCourse);
    }

    /**
     * 新增生产流程操作
     */
    @Log(title = "生产流程操作", businessType = BusinessType.INSERT)
    @PostMapping("/controls")
    public AjaxResult add(@RequestBody LwControls lwControls)
    {
        return toAjax(lwCourseService.insertLwControls(lwControls));
    }

    /**
     * 新增检测操作
     */
    @Log(title = "检测操作", businessType = BusinessType.INSERT)
    @PostMapping("/detection")
    public AjaxResult addDetection(@RequestBody LwDetection lwDetection)
    {
        return toAjax(lwCourseService.insertLwDetection(lwDetection));
    }

    /**
     * 修改生产过程管理
     */
    @PreAuthorize("@ss.hasPermi('course:course:edit')")
    @Log(title = "生产过程管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LwCourse lwCourse)
    {
        return toAjax(lwCourseService.updateLwCourse(lwCourse));
    }

    /**
     * 删除生产过程管理
     */
    @PreAuthorize("@ss.hasPermi('course:course:remove')")
    @Log(title = "生产过程管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lwCourseService.deleteLwCourseByIds(ids));
    }

    @DeleteMapping("delDialogue/{id}")
    public AjaxResult delDialogue(@PathVariable Long id)
    {
        return toAjax(lwCourseService.delDialogue(id));
    }

    @PostMapping("/getIsInStock/{id}")
    public boolean getIsInStock(@PathVariable("id") Long id){
        return lwCourseService.getIsInStock(id);
    }
}
